﻿Namespace EIBData
    Public Class EIBDataDPT_Info

        Sub New(Name As String, BaseName As String, Number As String, OctetLength As Byte, Type As Type)
            _DPT_Name = Name
            _DPT_BaseName = BaseName
            _DPT_Number = Number
            _DPT_OctetLength = OctetLength
            _DPT_Type = Type
        End Sub


        Private _DPT_Name As String = ""
        Public ReadOnly Property DPT_Name As String
            Get
                Return _DPT_Name
            End Get
        End Property

        Private _DPT_BaseName As String = ""
        Public ReadOnly Property DPT_BaseName As String
            Get
                Return _DPT_BaseName
            End Get
        End Property

        Private _DPT_Number As String = ""
        Public ReadOnly Property DPT_Number As String
            Get
                Return _DPT_Number
            End Get
        End Property

        Private _DPT_OctetLength As Byte = 0
        Public ReadOnly Property DPT_OctetLength As Byte
            Get
                Return _DPT_OctetLength
            End Get
        End Property

        Private _DPT_Type As Type = Nothing
        Public ReadOnly Property DPT_Type As Type
            Get
                Return _DPT_Type
            End Get
        End Property


        Public Shared Function GetDPTBases() As Dictionary(Of EIBDataDPT_Info, List(Of EIBDataDPT_Info))
            Dim d As New Dictionary(Of EIBDataDPT_Info, List(Of EIBDataDPT_Info))

            For Each t In System.Reflection.Assembly.GetAssembly(GetType(DPT.EIBDataDPT_Base)).GetTypes
                If t.IsSubclassOf(GetType(DPT.EIBDataDPT_Base)) Then
                    If t.Name.ToUpper.Contains("BASE") Then
                        d.Add(New EIBDataDPT_Info(t.GetProperty("DPT_Name").GetValue(Nothing, Nothing),
                                          t.GetProperty("DPT_BaseName").GetValue(Nothing, Nothing),
                                          t.GetProperty("DPT_Number").GetValue(Nothing, Nothing),
                                          t.GetProperty("DPT_OctetLength").GetValue(Nothing, Nothing),
                                          t), GetDPTSubs(t))
                    End If
                End If
            Next

            Return d
        End Function

        Private Shared Function GetDPTSubs(main As Type) As List(Of EIBDataDPT_Info)
            Dim l As New List(Of EIBDataDPT_Info)

            For Each t In System.Reflection.Assembly.GetAssembly(GetType(DPT.EIBDataDPT_Base)).GetTypes
                If t.IsSubclassOf(main) Then
                    l.Add(New EIBDataDPT_Info(t.GetProperty("DPT_Name").GetValue(Nothing, Nothing),
                                      main.GetProperty("DPT_BaseName").GetValue(Nothing, Nothing),
                                      t.GetProperty("DPT_Number").GetValue(Nothing, Nothing),
                                      main.GetProperty("DPT_OctetLength").GetValue(Nothing, Nothing),
                                      t))
                End If
            Next

            Return l
        End Function
    End Class
End Namespace